package com.xmh.myutil.othertest;

import com.xmh.myutil.util.FileUtil;
import com.xmh.myutil.util.NioReadUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.*;

public class ReadBookUtil {

    @Test
    public void readBookTest() throws InterruptedException, IOException {
        int charLength = 110;
//        int charLength = 76;

        long stopTime = 8000L;

        String bookPath = this.getClass().getResource("/other/frxxz2.txt").getPath();
//        String bookPath = this.getClass().getResource("/other/FanRenXiuXianZhuan(JingJiaoBan).txt").getPath();

        String bookMarkPath = this.getClass().getResource("/other/bookMarkpath.txt").getPath();

        StringBuffer fileStrBuf = NioReadUtils.readFile(bookPath, "UTF-8");

        String fileStr = fileStrBuf.toString();

        String fileStr1 = FileUtil.getFileStr(bookMarkPath);

        int endIndex = fileStr.indexOf(fileStr1);

        String replace = fileStr.replace(fileStr.substring(0, endIndex), "");

        String[] split = replace.split("\r\n");

        StringBuilder article = new StringBuilder();

        for (String oldStr : split) {
            if (StringUtils.isBlank(oldStr)) continue;

            StringBuilder stringBuilder = new StringBuilder(oldStr);

            if (oldStr.length() > charLength) {
                int limit = oldStr.length() / charLength + 1;

                for (int i = 1; i < limit; i++) {
                    stringBuilder.insert(charLength * i, "\n\n");
                }
            }

//            System.out.println(stringBuilder.append("\n"));
//            FileUtil.outFile(oldStr, bookMarkPath);
//            Thread.sleep(stopTime);
            article.append(stringBuilder.append("\n\n"));
        }
        System.out.println(replace(article.toString()));
    }

    private String replace(String str) {
        String replace = str;

        replace = replace.replace("为升吗", "为什么");
        replace = replace.replace("那吗", "那么");
        replace = replace.replace("sè", "色");
        replace = replace.replace("yīn", "阴");
        replace = replace.replace("rì", "日");
        replace = replace.replace("jīng", "精");
        replace = replace.replace("jǐng", "警");
        replace = replace.replace("shè", "射");
        replace = replace.replace("jiān", "奸");
        replace = replace.replace("cāo", "操");
        replace = replace.replace("zìyóu", "自由");
        replace = replace.replace("dúlì", "独立");
        replace = replace.replace("xìng", "性");
        replace = replace.replace("sāo", "骚");
        replace = replace.replace("chūn", "春");
        replace = replace.replace("yín", "淫");
        replace = replace.replace("yù", "欲");
        replace = replace.replace("chéngrén", "成人");
        replace = replace.replace("仈", "八");
        replace = replace.replace("jiǔ", "九");
        replace = replace.replace("xīzàng", "西藏");
        replace = replace.replace("rǔ", "乳");
        replace = replace.replace("cháo", "潮");
        replace = replace.replace("滴溜溜一转", "");
        replace = replace.replace("滴溜溜的", "");
        replace = replace.replace("----下", "");
        replace = replace.replace("惊人的一幕出现了", "---");
        replace = replace.replace("惊人一幕出现了", "---");
        replace = replace.replace("骇人的一幕出现了", "---");
        replace = replace.replace("不可思议的一幕出现了", "---");
        replace = replace.replace("几乎与此同时", "-同时-");
        replace = replace.replace("面色大变，", "--");
        replace = replace.replace("同一时间", "-同时-");
        replace = replace.replace("轰隆隆”的一阵低沉闷响后", "---");
        replace = replace.replace("十指连弹", "---");

        return replace;
    }


}
